<%--
  Created by IntelliJ IDEA.
  User: 叶叶
  Date: 2022/2/19
  Time: 14:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>生产计划设计</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
    <script src="../js/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>


<DIV class=DIV_STYLE2><TABLE cellSpacing=0 cellPadding=0 width=350 align=center bgColor=#ffffff border=0>
    <div style="position: relative;left: 60%" id="queren">

        <INPUT   data-toggle="modal" data-target="#myModal"  type=button value=添加产品>
        <INPUT  onclick=delSelect() type=button value=删除产品>
        <INPUT onclick="yuelan()" type=submit value=预览>
        <INPUT onmouseup="this.className='btn3_mouseup'" onclick=fanhui() onmouseover="this.className='btn3_mouseover'" onmousedown="this.className='btn3_mousedown'" onmouseout="this.className='btn3_mouseout'" class=btn3_mouseout type=button value=返回>
    </div>
    <TBODY>
    <TR>
        <TD class=TABLE_STYLE6 vAlign=bottom rowSpan=2 align=center>
            <TABLE style="BORDER-TOP: #333333 1px solid; BORDER-RIGHT: #333333 1px solid; BORDER-BOTTOM: #333333 1px solid; BORDER-LEFT: #333333 1px solid" cellSpacing=0 cellPadding=0 width=1000 border=0>
                <TBODY>
                <TR>
                    <TD height=10 colSpan=4>
                        <TABLE width=1000>
                            <TBODY>
                            <TR>
                                <TD>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE5 height=5 align=center>&nbsp;</TD></TR></TBODY></TABLE>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE5 height=5 align=center><FONT size=4><B>生产计划单</B></FONT></TD></TR></TBODY></TABLE>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE5 height=5 align=center>&nbsp;</TD></TR></TBODY></TABLE>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20><INPUT type=hidden name=payer_ID>
                                            <TD class=TD_STYLE8 borderColorLight=#848284 width="20%" borderColorDark=#eeeeee align=right>生产理由：</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="40%" align=left><INPUT type=hidden value=新发生 name=reason>新发生</TD>
                                            <TD class=TD_STYLE8 borderColorLight=#848284 width="20%" borderColorDark=#eeeeee align=right>供货时间：</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="40%" align=left><INPUT onfocus="" id=date_start type="date" class=INPUT_STYLE3 name=demand_gather_time></TD></TR>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE8 borderColorLight=#848284 width="9%" borderColorDark=#eeeeee align=right>登记人&nbsp;&nbsp;：</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="40%" align=left><INPUT class=INPUT_STYLE3 value=newer id="djr" name=register></TD>
                                            <TD class=TD_STYLE8 borderColorLight=#848284 width="15%" borderColorDark=#eeeeee align=right>登记时间：</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="40%" align=left><span id="shijian"></span></TD></TR></TBODY></TABLE>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE5 height=5 align=center>&nbsp;</TD></TR></TBODY></TABLE>
                                    <TABLE id=tableOnlineEdit class=TABLE_STYLE5 borderColor=#000000 cellSpacing=0 cols=1 borderColorDark=#eeeeee cellPadding=0 align=center borderColorLight=#848284 border=1>
                                        <THEAD>
                                        <TR class=TR_STYLE2 height=20 bgColor=#d2e9ff>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="5%" align=left>点选</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>产品名称 </TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="11%" align=left>产品编号 </TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>描述 </TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="11%" align=left>数量</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="8%" align=left>单位 </TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="11%" align=left>单价（元）</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="13%" align=left>小计（元）</TD></TR>






                                        </THEAD>
                                        <TBODY></TBODY></TABLE>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE5 height=5 align=center>&nbsp;</TD></TR></TBODY></TABLE>
                                    <TABLE class=TABLE_STYLE4 align=center>
                                        <TBODY>
                                        <TR class=TR_STYLE1 height=20>
                                            <TD class=TD_STYLE8 borderColorLight=#848284 width="9%" borderColorDark=#eeeeee align=right>备注&nbsp;&nbsp;&nbsp;&nbsp;：</TD>
                                            <TD class=TD_STYLE2 borderColor=#dedbd6 width="89%" align=left><TEXTAREA class=TEXTAREA_STYLE1 rows=4 cols=50 name=remark id="bz"></TEXTAREA> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
                <TR>
                    <TD width=56 colSpan=3 noWrap></TD></TD></TR>
                <TR>
                    <TD height=100 colSpan=3 noWrap></TD>
                    <TD></TD></TR>
                <TR vAlign=bottom>
                    <TD colSpan=4 noWrap align=center></TD></TR></TD>
                <TR>
                    <TD colSpan=4 noWrap align=right></TD></TR></TBODY></TABLE></TD>
        <TD bgColor=#ffffff height=2 width=1></TD>
        <TD bgColor=#ffffff height=2 width=1></TD>
        <TD bgColor=#ffffff height=2 width=1></TD></TR>
    <TR>
        <TD bgColor=#333333 height=120 width=1></TD>
        <TD bgColor=#666666 height=120 width=1></TD>
        <TD bgColor=#999999 height=120 width=1></TD></TR>
    <TR align=right vAlign=top>
        <TD colSpan=4>
            <TABLE class=TABLE_STYLE6 cellSpacing=0 cellPadding=0 align=center border=0>
                <TBODY>
                <TR>
                    <TD bgColor=#333333 height=1></TD></TR>
                <TR>
                    <TD bgColor=#666666 height=1></TD></TR>
                <TR>
                    <TD bgColor=#999999 height=1></TD></TR></TBODY></TABLE></TD></TR>
    <TR align=right vAlign=middle>
        <TD colSpan=4></TD></TR></TBODY></TABLE></DIV>
<!-- 模态框 -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title">模态框头部</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                <table id="table" border="1px" cellspacing="0" cellpadding="0" width="400px">

                </table>
            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<script>
    $(function () {
        var myDate = new Date();
        year = myDate.getYear()+1900;
        month = myDate.getMonth()+1;
        date = myDate.getDate();
        hour = myDate.getHours();
        minute =myDate.getMinutes();
        second = myDate.getSeconds();
        document.getElementById("shijian").innerText=year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
        $("#table").bootstrapTable({
            method: "post",
            //请求类型
            contentType: "application/json",
            //请求地址
            url: "/cha/shenc/",
            striped: true,
            //初始页数
            pageNumber: 1,
            pagination: true,
            sidePagination: "server",
            pageSize: 2,
            pageList: [2, 4, 6, 8, 10],
            queryParams: function (param) {
                return {
                    page: (param.offset / param.limit) + 1,
                    pageNum: param.limit
                }
            },
            columns: [
                {title: "产品编号", field: "productId", align: "center"},
                {title: "产品名称", field: "productName", align: "center"},
                {title: "用途类型", field: "type", align: "center",formatter:function (value) {
                        if (value == "Y001-1") {
                            return "商品";
                        }
                        if (value == "Y001-2") {
                            return "物料";
                        }
                    }},
                {title: "单位", field: "amountUnit", align: "center"},
                {title: "单价", field: "costPrice", align: "center"},
                {title: "生产", field: "", align: "center",
                    formatter: function (value, row, index) {
                        var btn2 = "<button class='btn btn-info'  onclick='tj(" + JSON.stringify(row) + ")'>生产</button>";
                        return btn2;
                    }
                }
            ]
        })
    })
    /*模态框添加物料*/
    function tj(it) {
        var type=""
        if (it.type == "Y001-1") {
            type = "商品";
        } else if (it.type == "Y001-2") {
            type = "物料";
        }
        document.getElementById("tableOnlineEdit").innerHTML+="<tr>" +
            "<td><input type='checkbox' name='car'/></td>" +
            "<td>"+it.productName+"</td>" +
            "<td>"+it.productId+"</td>" +
            "<td></td>" +
            "<td><input type='text' class='sl'></td>" +
            "<td>"+it.amountUnit+"</td>" +
            "<td>"+it.costPrice+"</td>" +
            "<td><input type='text' value='' id='jieguo' readonly='readonly'></td>" +
            "</tr>"
    }
    //模态框删除物料
    function delSelect() {
        let car = document.getElementsByName("car");
        for(let i=car.length-1;i>=0;i--){
            if (car[i].checked==true){
                car[i].parentNode.parentNode.parentNode.remove();
            }
        }
    }

    /*预览则是计算单价并显示在表格中*/
    function yuelan() {
        let nodeListOf = document.getElementById("tableOnlineEdit").querySelectorAll("tr");
        for(let i=0;i<nodeListOf.length-1;i++){
            let nodeListOf1 = nodeListOf[i+1].querySelectorAll("td");
            let a  =nodeListOf1[nodeListOf1.length-4].querySelectorAll("input")[0].value;
            let b=nodeListOf1[nodeListOf1.length-2].innerText
            let c=a*b;
            nodeListOf1[nodeListOf1.length-1].querySelectorAll("input")[0].value=c;
            console.log(i+"结果"+nodeListOf1[nodeListOf1.length-1].querySelectorAll("input")[0].value)
            document.getElementById("queren").innerHTML="<button onclick='tjsc()'>确认</button>"
        }
    }
    function tjsc() {
        let nodeListOf = document.getElementById("tableOnlineEdit").querySelectorAll("tr");
        for(let i=0;i<nodeListOf.length-1;i++){
            let nodeListOf1 = nodeListOf[i+1].querySelectorAll("td");
            //产品名称
            let productName = nodeListOf1[nodeListOf1.length-7].innerText;
            //产品编号
            let productId = nodeListOf1[nodeListOf1.length-6].innerText;
            //单位
            let amountUnit = nodeListOf1[nodeListOf1.length-3].innerText;
            //数量
            let amount  =nodeListOf1[nodeListOf1.length-4].querySelectorAll("input")[0].value;
            //登记人
            let djr = document.getElementById("djr").value;
            //备注
            let bz = document.getElementById("bz").value;
            //登记时间
            let shijian = document.getElementById("shijian").innerText;
            var xxx={
                productName:productName,
                productId:productId,
                amountUnit:amountUnit,
                amount:amount,
                register:djr,
                remark:bz,
                registerTime:shijian,
                designer:djr
            }
            $.ajax({
                type:"post",
                dataType:"json",
                data:JSON.stringify(xxx),
                contentType: "application/json",
                url: "/cha/addjh/",
                success:function (data) {
                    document.location="productionplan.jsp"
                }
            })
        }
    }
</script>
</body>
</html>
